package com.tz.fruit.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* 订单实体类
*/
@Entity
@Table(name="FRUIT_ORDER")
public class Order implements Serializable{
	private Long orderId;//订单ID
	
	private String orderNo;//订单编号
	private Date createDate;//创建日期
	private Date payDate;//付款日期
	private double total;//订单总金额
	private OrderStatus orderStatus;//订单状态，枚举

	private String emailCode;//邮编
	private String reciver;//收件人
	private String tel;//联系方式
	private String address;//收货地址
	
	private int visable;//可见状态    默认 0：可见    1：不可见
	
	private Set<OrderItem> items;//订单中的商品明细
	private User user;//订单所属用户

	public Order() {
	}
	
	public Order(String orderNo, Date createDate, Date payDate, double total, OrderStatus orderStatus, String emailCode,
			String reciver, String tel, String address, int visable, Set<OrderItem> items, User user) {
		super();
		this.orderNo = orderNo;
		this.createDate = createDate;
		this.payDate = payDate;
		this.total = total;
		this.orderStatus = orderStatus;
		this.emailCode = emailCode;
		this.reciver = reciver;
		this.tel = tel;
		this.address = address;
		this.visable = visable;
		this.items = items;
		this.user = user;
	}



	@Id
	@GeneratedValue
	public Long getOrderId() {
		return orderId;
	}

	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}
	@Column(nullable=false,unique=true)
	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	@Temporal(TemporalType.TIMESTAMP)
	public Date getPayDate() {
		return payDate;
	}

	public void setPayDate(Date payDate) {
		this.payDate = payDate;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}
	@Enumerated(EnumType.STRING)
	public OrderStatus getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(OrderStatus orderStatus) {
		this.orderStatus = orderStatus;
	}

	public String getEmailCode() {
		return emailCode;
	}

	public void setEmailCode(String emailCode) {
		this.emailCode = emailCode;
	}

	public String getReciver() {
		return reciver;
	}

	public void setReciver(String reciver) {
		this.reciver = reciver;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public int getVisable() {
		return visable;
	}

	public void setVisable(int visable) {
		this.visable = visable;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	@OneToMany(mappedBy="order",cascade=CascadeType.ALL)
	public Set<OrderItem> getItems() {
		return items;
	}

	public void setItems(Set<OrderItem> items) {
		this.items = items;
	}
	
	@ManyToOne
	@JoinColumn(name="userId")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((orderId == null) ? 0 : orderId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Order other = (Order) obj;
		if (orderId == null) {
			if (other.orderId != null)
				return false;
		} else if (!orderId.equals(other.orderId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Order [orderId=" + orderId + ", orderNo=" + orderNo + ", createDate=" + createDate + ", payDate="
				+ payDate + ", total=" + total + ", orderStatus=" + orderStatus + ", emailCode=" + emailCode
				+ ", reciver=" + reciver + ", tel=" + tel + ", address=" + address + ", visable=" + visable + "]";
	}

}
